package com.arcvideo.acsplayer.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageButton;

import com.arcvideo.acsplayer.R;

public class GyroHDControlView extends FrameLayout {

	public static final int STATE_FORWORD = 1;
	public static final int STATE_BACKWORD = 2;

	private Context mContext = null;

	private ImageButton mControlGyroButton = null;
	private Button mControlHDButton = null;

	private int mRotationType = 0;
	private boolean mbVRMode = false;

	private GyroHDControlInterface mGyroHDControlInterface = null;

	/**
	 * 回调接口
	 *
	 * @author skl5250
	 *
	 */
	public interface GyroHDControlInterface {
		public void clickControlGyro();

		public void clickControlHD();
	}

	/**
	 * 按键事件
	 */
	private OnClickListener mOnClickListener = new OnClickListener() {

		@Override
		public void onClick(View view) {
			switch (view.getId()) {
				case R.id.control_gyro :
					if (null != mGyroHDControlInterface)
						mGyroHDControlInterface.clickControlGyro();

					break;
				case R.id.control_hd :
					if (null != mGyroHDControlInterface)
						mGyroHDControlInterface.clickControlHD();

					break;
				default :
					break;
			}
			setVisibility(View.GONE);
		}
	};

	/**
	 * 构造函数
	 *
	 * @param context
	 */
	public GyroHDControlView(Context context) {
		super(context);
		mContext = context;
	}

	/**
	 * 构造函数
	 *
	 * @param context
	 * @param attributeSet
	 */
	public GyroHDControlView(Context context, AttributeSet attributeSet) {
		super(context, attributeSet);
		mContext = context;
	}

	/**
	 * 初始化
	 *
	 * @param rotationType
	 * @param isVRMode
	 * @param gyroHDControlInterface
	 */
	public void init(int rotationType, boolean isVRMode, GyroHDControlInterface gyroHDControlInterface) {
		mRotationType = rotationType;
		mbVRMode = isVRMode;
		mGyroHDControlInterface = gyroHDControlInterface;

		LayoutInflater.from(mContext).inflate(R.layout.actionbar_setting_port, this);

		initUI();
	}

	/**
	 * 初始化UI
	 */
	public void initUI() {
		mControlGyroButton = (ImageButton) findViewById(R.id.control_gyro);
		mControlGyroButton.setOnClickListener(mOnClickListener);
		mControlHDButton = (Button) findViewById(R.id.control_hd);
		mControlHDButton.setOnClickListener(mOnClickListener);
	}

	/**
	 * 显示
	 */
	public void show() {
		setVisibility(View.VISIBLE);
	}

	/**
	 * 隐藏
	 */
	public void hide() {
		setVisibility(View.INVISIBLE);
	}

	/**
	 * 设置画质状态
	 *
	 * @param state
	 */
	public void setQualityState(String state) {
		if (HDselectView.STATE_4K.equals(state))
			mControlHDButton.setText(R.string.clarity_4K);
		else if (HDselectView.STATE_ULTRA_CLEAR.equals(state))
			mControlHDButton.setText(R.string.clarity_ultra_clear);
		else if (HDselectView.STATE_HD.equals(state))
			mControlHDButton.setText(R.string.clarity_hd);
		else if (HDselectView.STATE_SD.equals(state))
			mControlHDButton.setText(R.string.clarity_sd);
		else if (HDselectView.STATE_SMOOTH.equals(state))
			mControlHDButton.setText(R.string.clarity_smooth);
	}

	/**
	 * 设置陀螺仪状态
	 *
	 * @param isOn
	 */
	public void setGyroState(boolean isOn) {
		if (isOn) {
			mControlGyroButton.setBackgroundResource(R.drawable.btn_gyro_p);
		} else {
			mControlGyroButton.setBackgroundResource(R.drawable.btn_gyro_n);
		}
	}
}